<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMap"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :defaultEventKey="defaultEventKey"
      :labelWidth="75"
    ></Ht-search-form>

    <ht-table
      :defaultEventKey="defaultEventKey"
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="140px">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>基本信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="交易流水号" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文标识号" prop="pkgId">
                <el-input v-model="detailForm.pkgId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="批序号" prop="batchNo">
                <el-input v-model="detailForm.batchNo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="cpgdate">
                <el-date-picker
                  v-model="detailForm.cpgdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker
                  v-model="detailForm.workdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务类型" prop="bizTypeCode">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.bizTypeCode === null || detailForm.bizTypeCode === undefined
                      ? ''
                      : detailForm.bizTypeCode + '-' + detailForm.bizTypeCodeDesc
                  "
                  placeholder="业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="业务种类" prop="bizCtgyCode">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.bizCtgyCode === null || detailForm.bizCtgyCode === undefined
                      ? ''
                      : detailForm.bizCtgyCode + '-' + detailForm.bizCtgyCodeDesc
                  "
                  placeholder="业务种类"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="来往账标识" prop="drct">
                <el-select style="width: 100%" v-model="detailForm.drct" placeholder="来往账标识" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.DRCTCODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="协议号" prop="protoId">
                <el-input v-model="detailForm.protoId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="货币种类" prop="curcd">
                <el-input v-model="detailForm.curcd" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="金额" prop="amount">
                <ht-amount-input v-model="detailForm.amount" placeholder="金额" :disable="true"></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="统一社会信用代码" prop="uniformScCode">
                <el-input v-model="detailForm.uniformScCode" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="地域标识" prop="regionid">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.regionid === null || detailForm.regionid === undefined
                      ? ''
                      : detailForm.regionid + '-' + detailForm.regionidDesc
                  "
                  placeholder="地域标识"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="征收机关代码" prop="orgId">
                <el-input v-model="detailForm.orgId" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="征收机关提交日期" prop="orgCmDate">
                <el-date-picker
                  v-model="detailForm.orgCmDate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="征收机关流水号" prop="orgNum">
                <el-input v-model="detailForm.orgNum" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>付款人信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款行行号" prop="payerBrno">
                <el-input v-model="detailForm.payerBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款行行名" prop="payerBrname">
                <el-input v-model="detailForm.payerBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款清算行行号" prop="payerStBrno">
                <el-input v-model="detailForm.payerStBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款清算行行名" prop="payerStBrname">
                <el-input v-model="detailForm.payerStBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人账号" prop="payerActno">
                <el-input v-model="detailForm.payerActno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款人名称" prop="payerName">
                <el-input v-model="detailForm.payerName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款客户标识" prop="payerId">
                <el-input v-model="detailForm.payerId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款方动账标识" prop="payerAccChgFlg">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.payerAccChgFlg"
                  placeholder="付款方动账标识"
                  :disabled="true"
                >
                  <el-option
                    v-for="dict in dictMap.Acc_Chg_Flg_Code"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="扣款通知编号" prop="dbtNo">
                <el-input v-model="detailForm.dbtNo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人客户结算名称" prop="payerInName">
                <el-input v-model="detailForm.payerInName" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款人客户结算账号" prop="payerInActno">
                <el-input v-model="detailForm.payerInActno" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>收款人信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款行行号" prop="payeeBrno">
                <el-input v-model="detailForm.payeeBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款行行名" prop="payeeBrname">
                <el-input v-model="detailForm.payeeBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款清算行行号" prop="payeeStBrno">
                <el-input v-model="detailForm.payeeStBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款清算行行名" prop="payeeStBrname">
                <el-input v-model="detailForm.payeeStBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款人账号" prop="payeeActno">
                <el-input v-model="detailForm.payeeActno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款人名称" prop="payeeName">
                <el-input v-model="detailForm.payeeName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款方金融账户标识" prop="payeeAccFlg">
                <el-input v-model="detailForm.payeeAccFlg" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款方动账标识" prop="payeeAccChgFlg">
                <el-select
                  style="width: 100%"
                  v-model="detailForm.payeeAccChgFlg"
                  placeholder="收款方动账标识"
                  :disabled="true"
                >
                  <el-option
                    v-for="dict in dictMap.Acc_Chg_Flg_Code"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="入账通知编号" prop="crdNo">
                <el-input v-model="detailForm.crdNo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款人客户结算名称" prop="payeeInName">
                <el-input v-model="detailForm.payeeInName" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款人客户结算账号" prop="payeeInActno">
                <el-input v-model="detailForm.payeeInActno" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>其他信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="退汇原因" prop="retnContent">
                <el-input type="textarea" v-model="detailForm.retnContent" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="备注" prop="remarks">
                <el-input type="textarea" v-model="detailForm.remarks" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="中心状态" prop="procStatus">
                <el-select style="width: 100%" v-model="detailForm.procStatus" placeholder="中心状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="业务状态" prop="status">
                <el-select style="width: 100%" v-model="detailForm.status" placeholder="业务状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.TXN_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="核验标识" prop="checkId">
                <el-select style="width: 100%" v-model="detailForm.checkId" placeholder="核验标识" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.CHECKFLAG"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="接收时间" prop="rcvTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.rcvTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>应答信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务回执状态" prop="bizStatus">
                <el-select style="width: 100%" v-model="detailForm.bizStatus" placeholder="业务回执状态">
                  <el-option
                    v-for="dict in dictMap.PROCESSSTATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="8">
              <el-form-item label="业务拒绝处理码" prop="bizRejectCode">
                <el-input
                  v-model="detailForm.bizRejectCode"
                  placeholder="请输入业务拒绝处理码"
                  @change="getbase('REJECTCODE')"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-input v-model="detailForm.bizRejectCodeDesc" :disabled="true" />
            </el-col>
            <el-col :span="4">
              <el-row>
                <el-button type="primary" icon="el-icon-search" plain @click="openBasedataDialog('REJECTCODE')">
                  请选择
                </el-button>
              </el-row>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="业务拒绝信息" prop="bizRejectInfo">
                <el-input type="textarea" v-model="detailForm.bizRejectInfo" maxlength="105" show-word-limit/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务处理参与机构" prop="bizProOrg">
                <el-input v-model="detailForm.bizProOrg" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="save">提 交</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <base-data-dialog ref="basedataDialog" @confirm="confirmData"></base-data-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigEntry,
  realtimeCollectionPaymentServiceReplyEntryDetail,
  realtimeCollectionPaymentServiceReplyEntrySave,
} from "@/api/cnaps/beps/385";
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import { getBasedata } from "@/api/cnaps/common/basedata";
import BaseDataDialog from "@/views/components/BasedataDialog";

export default {
  name: "RealtimeCollectionPaymentServiceReplyQuery",
  mixins: [listPageMixin],
  components: { HtAmountInput, BaseDataDialog },
  data() {
    return {
      defaultEventKey: "defaultEventKey",
      // 查询参数
      queryParams: {
        startcpgdate: undefined,
        endcpgdate: undefined,
        startworkdate: undefined,
        endworkdate: undefined,
        id: undefined,
        payerActno: undefined,
        payeeActno: undefined,
        batchNo: undefined,
        protoId: undefined,
      },
      // 搜索
      formOptions: [],
      //
      searchFormDictList: [
        "DRCTCODE",
        "Acc_Chg_Flg_Code",
        "PROCESSSTATUS",
        "PKG_STATUS",
        "TXN_STATUS",
        "CHECKFLAG",
        "PAYER_RT_STATUS_389",
      ],
      // 列信息
      regConfig: apiUrlConfigEntry,

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "cpgdate", label: "CPG日期", type: "date", width: 120 },
        { prop: "workdate", label: "工作日期", type: "date", width: 120 },
        {
          prop: "bizTypeCode",
          label: "业务类型",
          formatter(row, text, index) {
            return (
              (row["bizTypeCode"] === null || row["bizTypeCode"] === undefined ? "" : row["bizTypeCode"]) +
              "-" +
              (row["bizTypeCodeDesc"] === null || row["bizTypeCodeDesc"] === undefined ? "" : row["bizTypeCodeDesc"])
            );
          },
          width: 180,
        },
        { prop: "batchNo", label: "批序号", width: 120 },
        { prop: "payerActno", label: "付款人账号", width: 180 },
        { prop: "payeeActno", label: "收款人账号", width: 180 },
        { prop: "protoId", label: "协议号", width: 120 },
        { prop: "amount", label: "金额", type: "price", width: 120 },
        { prop: "status", label: "通讯状态", dictCode: "PKG_STATUS", width: 120 },
      ],

      loading: false,
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      restitle: "",
      // 是否显示弹出层
      open: false,
      resopen: false,
      // 表单参数
      detailForm: {},
      resdetailForm: {},
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
      rules: {
        bizStatus: { required: true, message: "请输入业务回执状态", trigger: "blur" },
      },
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "dates",
        nameObj: {
          startTimeName: "startcpgdate",
          endTimeName: "endcpgdate",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "startworkdate",
          endTimeName: "endworkdate",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "input",
        prop: "id",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },

      {
        type: "input",
        prop: "payerActno",
        defaultAttr: {
          size: "small",
          label: "付款人账号",
          placeholder: "请输入付款人账号",
        },
      },

      {
        type: "input",
        prop: "payeeActno",
        defaultAttr: {
          size: "small",
          label: "收款人账号",
          placeholder: "请输入收款人账号",
        },
      },

      {
        type: "input",
        prop: "batchNo",
        defaultAttr: {
          size: "small",
          label: "批序号",
          placeholder: "请输入批序号",
        },
      },
      {
        type: "input",
        prop: "protoId",
        defaultAttr: {
          size: "small",
          label: "协议号",
          placeholder: "请输入协议号",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */

    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },
    rescancel() {
      this.resopen = false;
    },
    /** 原交易明细按钮操作 */
    handleDetail(row) {
      realtimeCollectionPaymentServiceReplyEntryDetail(row).then((response) => {
        this.title = " 实时代收代付业务应答录入明细";
        this.detailForm = response.result;
        this.open = true;
      });
    },

    openBasedataDialog(dataType = "") {
      this.$refs.basedataDialog.show(dataType);
    },

    confirmData(fromFlag, row) {
      this.$set(this.detailForm, "bizRejectCode", row.dataValue);
      this.$set(this.detailForm, "bizRejectCodeDesc", row.dataDesc);
    },
    //回车获取basedata值
    getbase(dataType) {
      const dataValue = this.detailForm.bizRejectCode;
      getBasedata(dataType, dataValue)
        .then((response) => {
          if (response.code == "S" && response.result !== null && response.result !== undefined) {
            this.$set(this.detailForm, "bizRejectCode", response.result.dataValue);
            this.$set(this.detailForm, "bizRejectCodeDesc", response.result.dataDesc);
          } else {
            this.msgSuccess("找不到对应的字典项");
            this.$set(this.detailForm, "bizRejectCode", null);
            this.$set(this.detailForm, "bizRejectCodeDesc", null);
          }
        })
        .catch((err) => {
          this.$set(this.detailForm, "bizRejectCode", null);
          this.$set(this.detailForm, "bizRejectCodeDesc", null);
        });
    },

    save() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          realtimeCollectionPaymentServiceReplyEntrySave(this.detailForm)
            .then((res) => {
              this.loading = true;
              this.msgSuccess("提交成功");
              this.open = false;
              this.loading = false;
              this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
                confirmButtonText: "确定",
                callback: (action) => {
                },
              });
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
